home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
et
/
et3_0-a1.lha
/
et3
/
src
/
LOOKS
/
EtLook.C
next >
Wrap
C/C++ Source or Header
|
1992-07-06
|
18KB
|
682 lines
#ifdef __GNUG__
#pragma implementation
#endif
#include "EtLook.h"
#include "Env.h"
#include "WindowSystem.h"
#include "Expander.h"
#include "Buttons.h"
#include "Layout.h"
#include "Math.h"
static u_short UpArrowBits[]= {
# include "images/UpArrow.image"
};
static u_short InvUpArrowBits[]= {
# include "images/UpArrowInv.image"
};
static u_short DownArrowBits[]= {
# include "images/DownArrow.image"
};
static u_short InvDownArrowBits[]= {
# include "images/DownArrowInv.image"
};
static u_short LeftArrowBits[]= {
# include "images/LeftArrow.image"
};
static u_short InvLeftArrowBits[]= {
# include "images/LeftArrowInv.image"
};
static u_short RightArrowBits[]= {
# include "images/RightArrow.image"
};
static u_short InvRightArrowBits[]= {
# include "images/RightArrowInv.image"
};
static u_short menuArrowBits[]= {
# include "images/menuarrow.image"
};
static u_short RadioButtonOnBits[]= {
# include "images/RadioButtonOn.image"
};
static u_short RadioButtonOffBits[]= {
# include "images/RadioButtonOff.image"
};
static u_short RadioButtonFeedbackBits[]= {
# include "images/RadioButtonFeedback.image"
};
static u_short CheckMarkOnBits[]= {
# include "images/CheckmarkOn.image"
};
static u_short CheckMarkOffBits[]= {
# include "images/CheckmarkOff.image"
};
static u_short CheckMarkFeedbackBits[]= {
# include "images/CheckmarkInv.image"
};
static u_short CheckMarkBits[]= {
# include "images/Checkmark.image"
};
static u_short StretchBoxNEBits[]= {
# include "images/StretchBoxNE.image"
};
static u_short StretchBoxNWBits[]= {
# include "images/StretchBoxNW.image"
};
static u_short StretchBoxSEBits[]= {
# include "images/StretchBoxSE.image"
};
static u_short StretchBoxSWBits[]= {
# include "images/StretchBoxSW.image"
};
//---- ETLook ------------------------------------------------------------------
ETLook *gET;
Look *MakeEtLook()
{
return new ETLook;
}
//---- ETMenuBorderLayout ------------------------------------------------------
class ETMenuBorderLayout : public Layout {
int shadow;
public:
ETMenuBorderLayout(int shad)
{ shadow= shad; }
void SetOrigin(VObject*, Point);
void SetExtent(VObject*, Point);
Metric GetMinSize(VObject *acv);
void Adorn(VObject *acv, Rectangle &r, int code);
};
Metric ETMenuBorderLayout::GetMinSize(VObject *acv)
{
Point e= acv->At(0)->GetMinSize().extent + 2*gPoint2 + shadow;
if (acv->Size() > 1) {
Metric tm= acv->At(1)->GetMinSize();
e.x= Math::Max(e.x, tm.extent.x);
e.y+= tm.extent.y;
}
return e;
}
void ETMenuBorderLayout::SetExtent(VObject *acv, Point e)
{
e-= 2*gPoint2 + shadow;
if (acv->Size() > 1) {
acv->At(1)->CalcExtent();
e.y-= acv->At(1)->Height();
}
acv->At(0)->SetExtent(e);
}
void ETMenuBorderLayout::SetOrigin(VObject *acv, Point at)
{
at+= gPoint2;
if (acv->Size() > 1) {
int x= (acv->Width()-(4+shadow)-acv->At(1)->Width())/2;
acv->At(1)->SetOrigin(Point(at.x+x, at.y));
at.y+= acv->At(1)->Height();
}
acv->At(0)->SetOrigin(at);
}
void ETMenuBorderLayout::Adorn(VObject *acv, Rectangle &r, int)
{
Rectangle rr(acv->contentRect);
rr.extent-= shadow;
GrPaintRect(rr, gET->backgroundColor);
if (! acv->At(0)->contentRect.ContainsRect(r)) {
Ink *pat= shadow == 1 ? ePatBlack : ePatGrey50;
GrPaintRect(Rectangle(rr.origin.x+rr.extent.x, rr.origin.y+shadow, shadow, rr.extent.y), pat);
GrPaintRect(Rectangle(rr.origin.x+shadow, rr.origin.y+rr.extent.y, rr.extent.x, shadow), pat);
GrSetPenNormal();
GrStrokeRect(rr);
if (acv->Size() > 1) {
Rectangle cr(r);
cr.extent-= shadow;
cr.extent.y= acv->At(1)->Height();
cr= cr.Inset(2);
if (GrHasColor())
GrPaintRect(cr, gET->menuTitleColor);
acv->At(1)->DrawAll(r);
if (!GrHasColor())
GrPaintRect(cr, gET->menuTitleColor);
}
}
acv->At(0)->DrawAll(r);
}
//---- ETMenuLineLayout --------------------------------------------------------
class ETMenuLineLayout : public Layout {
public:
ETMenuLineLayout()
{ }
Metric GetMinSize(VObject*)
{ return gPoint1; }
void Adorn(VObject *acv, Rectangle&, int)
{ GrPaintRect(acv->contentRect, ePatGrey50); }
};
//---- ETScrollButtonLayout ----------------------------------------------------
class ETScrollButtonLayout : public Layout {
public:
ETScrollButtonLayout()
{ }
Metric GetMinSize(VObject*)
{ return 16 + gPoint4; }
void Adorn(VObject *acv, Rectangle &r, int code);
};
void ETScrollButtonLayout::Adorn(VObject*, Rectangle &r, int code)
{
GrShowBitMap(r.Inset(2), gET->arrows[code & 0x03]);
if (TESTBIT(code, 4))
GrPaintBitMap(r.Inset(2), gET->invarrows[code & 0x03], gHighlightColor);
}
//---- ETToggleButtonLayout ----------------------------------------------------
class ETToggleButtonLayout : public Layout {
Bitmap *on, *off, *highlight;
public:
ETToggleButtonLayout(Bitmap *b1, Bitmap *b2, Bitmap *b3)
{ on= b1; off= b2; highlight= b3; }
Metric GetMinSize(VObject *acv);
void Adorn(VObject *acv, Rectangle &r, int code);
void SetOrigin(VObject *acv, Point at);
};
Metric ETToggleButtonLayout::GetMinSize(VObject *acv)
{
Metric m(on->Size(), 12);
if (acv->Size() > 0)
m= HCat(m, acv->At(0)->GetMinSize(), 6);
return m;
}
void ETToggleButtonLayout::SetOrigin(VObject *acv, Point at)
{
if (acv->Size() > 0) {
at.x+= on->Size().x+6;
acv->At(0)->SetOrigin(at);
}
}
void ETToggleButtonLayout::Adorn(VObject *acv, Rectangle &r, int code)
{
Rectangle rr(acv->GetOrigin(), on->Size());
if (acv->Size() > 0) {
acv->At(0)->DrawAll(r);
rr.origin.y+= GetMinSize(acv).base - 12;
}
if (TESTBIT(code, 3))
GrPaintBitMap(rr, highlight, gHighlightColor);
GrPaintBitMap(rr, TESTBIT(code, 1) ? on : off,
TESTBIT(code, 2) ? ePatBlack : gET->disableInk);
}
//---- ETMenuItemLayout ------------------------------------------------------
class ETMenuItemLayout : public Layout {
public:
ETMenuItemLayout()
{ }
Metric GetMinSize(VObject *acv);
void SetOrigin(VObject *acv, Point at);
void Adorn(VObject *acv, Rectangle &r, int code);
};
Metric ETMenuItemLayout::GetMinSize(VObject *acv)
{
Metric m= acv->At(0)->GetMinSize();
m.extent.x+= 2+gET->CheckMark->Size().x+4+11;
return m;
}
void ETMenuItemLayout::SetOrigin(VObject *acv, Point at)
{
if (acv->Size() > 0) {
at.x+= 2+gET->CheckMark->Size().x+4;
acv->At(0)->SetOrigin(at);
}
}
void ETMenuItemLayout::Adorn(VObject *acv, Rectangle &r, int code)
{
Rectangle cr(acv->contentRect),
rr(cr.origin, gET->CheckMark->Size());
Ink *ink= TESTBIT(code, 5) ? ePatBlack : gET->disableInk;
if (TESTBIT(code, 3) && GrHasColor())
GrPaintRect(cr, gHighlightColor);
if (acv->Size() > 0)
acv->At(0)->DrawAll(r);
if (TESTBIT(code, 4)) {
Rectangle rr(gET->menuArrow->Size());
rr.origin= cr.NE()-Point(11,-4);
GrPaintBitMap(rr, gET->menuArrow, ink);
}
if ((code & 3) && TESTBIT(code, 2)) {
rr.origin.x+= 2;
rr.origin.y+= (cr.extent.y-gET->CheckMark->Size().y)/2;
GrPaintBitMap(rr, gET->CheckMark, ink);
}
if (TESTBIT(code, 3) && !GrHasColor())
GrPaintRect(cr, gHighlightColor);
}
//---- ETScrollBarLayout -------------------------------------------------------
class ETScrollBarLayout : public Layout {
public:
ETScrollBarLayout()
{ }
void Adorn(VObject *acv, Rectangle &r, int code);
};
void ETScrollBarLayout::Adorn(VObject *acv, Rectangle &r, int)
{
((Expander*)acv)->Expander::Draw(r);
GrSetPenNormal();
GrStrokeRect(r);
GrSetPenNormal();
}
//---- ETActionButtonLayout ----------------------------------------------------
class ETActionButtonLayout : public Layout {
Point border;
bool dflt;
public:
ETActionButtonLayout(bool d)
{ dflt= d; }
void Adorn(VObject *acv, Rectangle &r, int code);
Metric GetMinSize(VObject *acv)
{ return acv->At(0)->GetMinSize().Expand(gPoint6); }
};
void ETActionButtonLayout::Adorn(VObject *acv, Rectangle &r, int code)
{
Rectangle rr(r.Inset(4));
VObject *vop= acv->At(0);
if (! TESTBIT(code, 2))
GrSetPenInk(gET->disableInk);
if (GrHasColor() && (TESTBIT(code, 1) || TESTBIT(code, 3)))
GrPaintRoundRect(rr, 14, gHighlightColor);
vop->DrawAll(r);
if (!GrHasColor() && (TESTBIT(code, 1) || TESTBIT(code, 3)))
GrPaintRoundRect(rr, 14, gHighlightColor);
GrStrokeRoundRect(rr, 14);
if (dflt) {
GrSetPenSize(2);
GrStrokeRoundRect(r, 18);
}
GrSetPenNormal();
}
//---- ETPopupButtonLayout -----------------------------------------------------
class ETPopupButtonLayout : public Layout {
public:
ETPopupButtonLayout()
{ }
void Adorn(VObject *acv, Rectangle &r, int code);
};
void ETPopupButtonLayout::Adorn(VObject *acv, Rectangle&, int)
{
Rectangle rr(acv->contentRect);
rr.extent-= gPoint1;
rr.origin+= gPoint1;
GrPaintLine(gET->shadowColor, 1, eDefaultCap, rr.SW(), rr.SE());
GrPaintLine(gET->shadowColor, 1, eDefaultCap, rr.NE(), rr.SE());
rr.origin-= gPoint1;
GrStrokeRect(rr);
}
//---- ETSliderLayout ----------------------------------------------------------
class ETSliderLayout : public Layout {
public:
ETSliderLayout()
{ }
void Adorn(VObject *acv, Rectangle &r, int code);
};
void ETSliderLayout::Adorn(VObject*, Rectangle &r, int)
{
GrPaintRect(r, ePatGrey12);
GrSetPenNormal();
GrStrokeRect(r);
}
//---- ETThumbLayout -----------------------------------------------------------
class ETThumbLayout : public Layout {
public:
ETThumbLayout()
{ }
Metric GetMinSize(VObject*)
{ return Metric(20); }
void Adorn(VObject *acv, Rectangle &r, int code);
};
void ETThumbLayout::Adorn(VObject*, Rectangle &r, int)
{
GrPaintRect(r, ePatGrey50);
GrStrokeRect(r);
}
//---- ETFieldBorderLayout --------------------------------------------------
class ETFieldBorderLayout : public Layout {
bool noborder;
public:
ETFieldBorderLayout(bool nb)
{ noborder= nb; }
void Adorn(VObject *acv, Rectangle &r, int code);
long GetValue(VObject*, int)
{ return noborder ? 1 : 2; }
};
void ETFieldBorderLayout::Adorn(VObject *acv, Rectangle&, int code)
{
int bw= 1;
if (noborder) {
if (!code)
bw= 0;
} else {
if (code)
bw= 2;
}
if (bw > 0)
GrGetPort()->StrokeRect(gInkBlack, bw, acv->contentRect);
}
//---- ETMenuBarLayout ---------------------------------------------------------
class ETMenuBarLayout : public Layout {
public:
ETMenuBarLayout()
{ }
Metric GetMinSize(VObject *acv)
{ return acv->At(0)->GetMinSize().Expand(gPoint1); }
void SetOrigin(VObject *acv, Point at)
{ acv->At(0)->SetOrigin(at+gPoint1); }
void SetExtent(VObject *acv, Point e)
{ acv->At(0)->SetExtent(e-gPoint2); }
void Adorn(VObject *acv, Rectangle&, int)
{ GrStrokeRect(acv->contentRect); }
};
//---- ETProgressBarLayout -----------------------------------------------------
class ETProgressBarLayout : public Layout {
public:
ETProgressBarLayout()
{ }
Metric GetMinSize(VObject*)
{ return Metric(200, 20); }
void Adorn(VObject *acv, Rectangle &r, int code);
};
void ETProgressBarLayout::Adorn(VObject *acv, Rectangle&, int val)
{
Rectangle rr(acv->contentRect);
rr.extent.x= val;
GrPaintRect(rr, ePatGrey50);
GrStrokeRect(acv->contentRect);
}
//---- ETScaleLayout -----------------------------------------------------------
class ETScaleLayout : public Layout {
public:
ETScaleLayout()
{ }
Metric GetMinSize(VObject *acv)
{ return acv->At(0)->GetMinSize(); }
void Adorn(VObject *acv, Rectangle &r, int code);
};
void ETScaleLayout::Adorn(VObject *acv, Rectangle&, int)
{
Rectangle cr= acv->contentRect;
GrStrokeRect(cr);
}
//---- ETFrameLayout -----------------------------------------------------------
class ETFrameLayout : public Layout {
public:
ETFrameLayout()
{ }
void Adorn(VObject *acv, Rectangle &r, int code);
long GetValue(VObject*, int code)
{ return code ? -1 : 1; }
};
void ETFrameLayout::Adorn(VObject*, Rectangle &r, int)
{
GrStrokeRect(r.Expand(gPoint1));
}
//---- ETScaleThumbLayout ------------------------------------------------------
class ETScaleThumbLayout : public Layout {
Direction dir;
public:
ETScaleThumbLayout(Direction d)
{ dir= d; }
Metric GetMinSize(VObject *acv);
void Adorn(VObject *acv, Rectangle &r, int code);
};
Metric ETScaleThumbLayout::GetMinSize(VObject*)
{
if (dir == eHor)
return Metric(20, 15);
return Metric(15, 20);
}
void ETScaleThumbLayout::Adorn(VObject *acv, Rectangle&, int)
{
GrPaintRect(acv->contentRect, ePatGrey50);
GrStrokeRect(acv->contentRect);
}
//---- ETGroupLayout -----------------------------------------------------------
class ETGroupLayout : public Layout {
Point border;
int cBorderTitleGap;
public:
ETGroupLayout()
{ border= gPoint6; cBorderTitleGap= 4; }
void SetOrigin(VObject*, Point);
void SetExtent(VObject*, Point);
Metric GetMinSize(VObject *acv);
void Adorn(VObject *acv, Rectangle &r, int code);
};
Metric ETGroupLayout::GetMinSize(VObject *acv)
{
VObject *interior= acv->At(0);
Metric m= interior->GetMinSize();
if (acv->Size() > 1) {
VObject *titleBar= acv->At(1);
Metric tm= titleBar->GetMinSize();
m.extent.x= Math::Max(m.extent.x, tm.extent.x+2*cBorderTitleGap);
int d= tm.extent.y - border.y;
if (d > 0) {
m.extent.y+= d;
m.base+= d;
}
}
return m.Expand(border);
}
void ETGroupLayout::SetExtent(VObject *acv, Point e)
{
if (acv->Size() > 1) {
VObject *titleBar= acv->At(1);
titleBar->CalcExtent();
int d= titleBar->Height() - border.y;
if (d > 0)
e.y-= d;
}
acv->At(0)->SetExtent(e-2*border);
}
void ETGroupLayout::SetOrigin(VObject *acv, Point at)
{
if (acv->Size() > 1) {
VObject *titleBar= acv->At(1);
int th= titleBar->Height();
int tgap= border.x+cBorderTitleGap;
titleBar->Align(Point(at.x+tgap, at.y), Metric(acv->Width()-2*tgap, th),
(VObjAlign)((eVObjHLeft & eVObjH) | eVObjVTop));
int d= th - border.y;
if (d > 0)
at.y+= d;
}
acv->At(0)->SetOrigin(at+border);
}
void ETGroupLayout::Adorn(VObject *acv, Rectangle &r, int)
{
if (! acv->At(0)->contentRect.ContainsRect(r)) {
if (acv->Size() > 1) {
VObject *titleBar= acv->At(1);
int h= titleBar->Height()/2-1;
Rectangle rr(acv->contentRect);
rr.origin.y+= h;
rr.extent.y-= h;
GrLine(Point(titleBar->GetOrigin().x, rr.origin.y), rr.NW());
GrLine(rr.NW(), rr.SW());
GrLine(rr.SW(), rr.SE());
GrLine(rr.SE(), rr.NE());
GrLine(rr.NE(), Point(titleBar->contentRect.NE().x, rr.origin.y));
} else
GrStrokeRect(acv->contentRect);
}
}
//---- ET++ --------------------------------------------------------------------
ETLook::ETLook()
{
gET= this;
if (gDepth > 1) {
shadowColor= new_Grey(0.5);
menuTitleColor= new_Grey(230);
windowHighlightColor= new_Grey(0.8);
} else {
shadowColor= ePatGrey50;
menuTitleColor= gInkXor;
windowHighlightColor= gInkXor;
}
arrows[0]= new Bitmap(16, UpArrowBits, 1);
arrows[1]= new Bitmap(16, DownArrowBits, 1);
arrows[2]= new Bitmap(16, LeftArrowBits, 1);
arrows[3]= new Bitmap(16, RightArrowBits, 1);
invarrows[0]= new Bitmap(16, InvUpArrowBits, 1);
invarrows[1]= new Bitmap(16, InvDownArrowBits, 1);
invarrows[2]= new Bitmap(16, InvLeftArrowBits, 1);
invarrows[3]= new Bitmap(16, InvRightArrowBits, 1);
menuArrow= new Bitmap(11, menuArrowBits, 1);
Point s(14, 13);
radioButtonOn= new Bitmap(s, RadioButtonOnBits);
radioButtonOff= new Bitmap(s, RadioButtonOffBits);
radioButtonFeedback= new Bitmap(s, RadioButtonFeedbackBits);
CheckMark= new Bitmap(Point(14,12), CheckMarkBits);
CheckMarkOn= new Bitmap(s, CheckMarkOnBits);
CheckMarkOff= new Bitmap(s, CheckMarkOffBits);
CheckMarkFeedback= new Bitmap(s, CheckMarkFeedbackBits);
StretchBoxNW= new Bitmap(8, StretchBoxNWBits);
StretchBoxNE= new Bitmap(8, StretchBoxNEBits);
StretchBoxSW= new Bitmap(8, StretchBoxSWBits);
StretchBoxSE= new Bitmap(8, StretchBoxSEBits);
popUpMenuLayout= new ETMenuBorderLayout(5);
pullDownMenuLayout= new ETMenuBorderLayout(1);
menuLineLayout= new ETMenuLineLayout;
menuItemLayout= new ETMenuItemLayout;
scrollButtonLayout= new ETScrollButtonLayout;
toggleButtonLayout= new ETToggleButtonLayout(CheckMarkOn, CheckMarkOff, CheckMarkFeedback);
radioButtonLayout= new ETToggleButtonLayout(radioButtonOn, radioButtonOff, radioButtonFeedback);
scrollBarLayout= new ETScrollBarLayout;
actionButtonLayout= new ETActionButtonLayout(FALSE);
defaultButtonLayout= new ETActionButtonLayout(TRUE);
popupButtonLayout= new ETPopupButtonLayout;
sliderLayout= new ETSliderLayout;
thumbLayout= new ETThumbLayout;
fieldBorderLayout= new ETFieldBorderLayout(FALSE);
fieldLayout= new ETFieldBorderLayout(TRUE);
menuBarLayout= new ETMenuBarLayout;
progressBarLayout= new ETProgressBarLayout;
scaleLayout= new ETScaleLayout;
scaleThumbLayout[eHor]= new ETScaleThumbLayout(eHor);
scaleThumbLayout[eVert]= new ETScaleThumbLayout(eVert);
groupLayout= new ETGroupLayout;
frameLayout= new ETFrameLayout;
}
ETLook::~ETLook()
{
for (int i= 0; i < 4; i++) {
SafeDelete(arrows[i]);
SafeDelete(invarrows[i]);
}
SafeDelete(menuArrow);
SafeDelete(radioButtonOn);
SafeDelete(radioButtonOff);
SafeDelete(radioButtonFeedback);
SafeDelete(CheckMarkOn);
SafeDelete(CheckMarkOff);
SafeDelete(CheckMarkFeedback);
SafeDelete(CheckMark);
SafeDelete(StretchBoxNW);
SafeDelete(StretchBoxNE);
SafeDelete(StretchBoxSW);
SafeDelete(StretchBoxSE);
}
void ETLook::DrawHighlight(Rectangle &r)
{
GrPaintRect(r, gHighlightColor);
}